function [out_logs] = eq_p_fun(p,data,c,scalefactor,supply,wave,ID_unique,unique_curr)

p_vec_logs = repmat(p,[length(ID_unique),1]);

dep_hat = exp(c.logME*(p_vec_logs+log(data.supply)) + ...
    c.short_increase*data.short_increase + ...
    c.long_decrease*data.long_decrease + ...
    c.currencies_potential*data.currencies_potential + ...
    c.incomenewdummy*data.incomenewdummy + c.agenewdummy*data.agenewdummy + ...
    c.countrynewdummy*data.countrynewdummy + ...
    c.type_objective*data.type_objective +...
    c.log_libor*data.log_libor + c.log_sp500*data.log_sp500 + c.cons +...
    c.pow*data.pow +...
    c.beta*data.beta + c.momentum4*data.momentum4);

w_hat = zeros(size(data,1),1);

for ii=1:length(ID_unique)
    
    temp_ind = find(data.household_id==ID_unique(ii));
        
    for cc=1:length(unique_curr)
        
        w_hat(temp_ind(cc)) = dep_hat(temp_ind(cc))./(1+nansum(dep_hat(temp_ind)));
        
    end
end

mktcap_hat = w_hat.*data.wealth;                    

mktcap_wave_hat = zeros(length(unique_curr),1);

for cc=1:length(unique_curr)
    
    temp_curr = (data.currency_id2==cc);
    
    mktcap_wave_hat(cc) = nansum(mktcap_hat(temp_curr&data.wave==wave));
    
    if mktcap_wave_hat(cc)==0
        
        mktcap_wave_hat(cc) = 10^-5;
    end
    
end

                                        
out_logs = log(mktcap_wave_hat) + log(scalefactor) - log(supply);

end

